package com.etc.controllers;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.cache.CacheProperties;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Date;

@RestController
public class HiController {


    @Value("${server.port}")
    private String port;

    @Resource(name="redisTemplate")
    RedisTemplate redisTemplate;

    @GetMapping("hi")
    public String hello() {

        ValueOperations<String, String> ops = redisTemplate.opsForValue();

        HashOperations<String, String, Object> hmops = redisTemplate.opsForHash();

        hmops.put("myobject", "name", "tom");
        hmops.put("myobject", "age", 10);
        hmops.put("myobject", "birthday", new Date());

        ops.set("mykey1", "hello");



        System.out.println(ops.get("mykey1"));
        return "我是：" + port + "data: hi";

    }

}
